package com.printeverywhere.action;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.util.ServletContextAware;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionContext;
import com.printeverywhere.delegator.AuctionServiceDelegator;
import com.printeverywhere.delegator.CategoryManagerServiceDelegator;
import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.delegator.CurrencyServiceDelegator;
import com.printeverywhere.delegator.ItemsServiceDelegator;
import com.printeverywhere.delegator.LocationCategoriesServiceDelegator;
import com.printeverywhere.delegator.TranslationSystemServiceDelegator;
import com.printeverywhere.dto.AdditionalCategories;
import com.printeverywhere.dto.AdditionalOptionsFees;
import com.printeverywhere.dto.AuctionListingFees;
import com.printeverywhere.dto.BidStatus;
import com.printeverywhere.dto.Currency;
import com.printeverywhere.dto.GeneralOptions;
import com.printeverywhere.dto.ItemAuctionImage;
import com.printeverywhere.dto.ItemAuctionImageId;
import com.printeverywhere.dto.ItemCategories;
import com.printeverywhere.dto.Items;
import com.printeverywhere.dto.Itemtype;
import com.printeverywhere.dto.Languages;
import com.printeverywhere.dto.ListingOptions;
import com.printeverywhere.dto.LocationCategoriesWOS;
import com.printeverywhere.dto.MiscellaneousFees;
import com.printeverywhere.dto.MyAccountCount;
import com.printeverywhere.dto.ShippingOptions;
import com.printeverywhere.dto.Transactions;
import com.printeverywhere.dto.UploadedFile;
import com.printeverywhere.dto.User;
import com.printeverywhere.util.AdminConstants;
import com.printeverywhere.util.AttributeConstants;
import com.printeverywhere.util.CommonUtil;
import com.printeverywhere.util.DateUtil;
import com.printeverywhere.util.SearchCriteria;
import com.printeverywhere.util.SessionUtil;

@SuppressWarnings("unchecked")
public class SellAction extends FrontBaseSupport implements ServletRequestAware, ServletContextAware {

	public SellAction() {
		super(false, false);
	}

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private MyAccountCount myAccountCount = new MyAccountCount();

	private List<Criterion> criterionList = new ArrayList<Criterion>();

	int count = 0;

	private HttpServletRequest request;

	private ServletContext servletContext;

	private List<Languages> languageList;

	private List<Currency> currency = CurrencyServiceDelegator.getList();

	private List<LocationCategoriesWOS> regionList = getRegionListByLevel();

	private List<LocationCategoriesWOS> countryList = getRegionListByLevel();

	private List<LocationCategoriesWOS> stateList = getRegionListByLevel();

	private List<ShippingOptions> shippingTimeList = getShippingOptionsById(1);

	private List<ShippingOptions> shippingCostChargesList = getShippingOptionsById(2);

	private List<ShippingOptions> shippingInsuranceList = getShippingOptionsById(3);

	private List<ShippingOptions> returnPeriodList = getShippingOptionsById(4);

	private List<ShippingOptions> refundMethodList = getShippingOptionsById(5);

	private List<ShippingOptions> shipToList = getShippingOptionsById(6);

	private File upload;

	private Integer thumbnailId;

	private Integer gallaryId;

	private String uploadContentType;

	private String uploadFileName;

	private double fees;

	private double fileFees;

	private double regularInsertionFees;

	private List<UploadedFile> uploadedFiles = new ArrayList<UploadedFile>();

	private String[] categories;

	private String[] backCategories;

	private String[] editCategories;

	private String[] editbackCategories;

	private String backAction;

	private Items items;

	private User user;
	private String action = "";

	private File[] file;
	private String myfileContentType;
	private String myfileFileName;

	private String defaultLang;

	private int defaultRegion;

	private int defaultCountry;

	private String defaultCurrency;

	public List<ShippingOptions> getShippingOptionsById(int id) {
		SearchCriteria searchCriteria = new SearchCriteria();

		searchCriteria.setAttribute("shippingOptionGroups.id", id);
		return (List<ShippingOptions>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, ShippingOptions.class);
	}

	/**
	 * @return the file
	 */
	public File[] getFile() {
		return file;
	}

	/**
	 * @param file the file to set
	 */
	public void setFile(File[] file) {
		this.file = file;
	}

	public List<LocationCategoriesWOS> getRegionListByLevel() {
		SearchCriteria searchListCriteria = new SearchCriteria();

		searchListCriteria.setOrderBy("categoryName");
		searchListCriteria.setAsc(true);
		searchListCriteria.setAttribute(AdminConstants.LEVEL, 1);
		return (List<LocationCategoriesWOS>) CommonFunctionDelegator.getObjectBySearchCriteria(searchListCriteria, LocationCategoriesWOS.class);
	}

	public String uploadFile() {
		if(request.getParameter("deleteAction") != null) {
			if(ActionContext.getContext().getSession().get("uploadedFiles") != null) {
				uploadedFiles = (List<UploadedFile>) ActionContext.getContext().getSession().get("uploadedFiles");
				uploadedFiles.remove(Integer.parseInt(request.getParameter("deleteAction")));
				ActionContext.getContext().getSession().put("uploadedFiles", uploadedFiles);
			}
		} else {
			File tempFile = null;
			try {
				if(ActionContext.getContext().getSession().get("uploadedFiles") != null) {
					uploadedFiles = (List<UploadedFile>) ActionContext.getContext().getSession().get("uploadedFiles");
				}

				int totalFileSize = 0;
				for (UploadedFile uploadedFile : uploadedFiles) {
					totalFileSize += (uploadedFile.getSize() / 1024);
				}
				ListingOptions listingOptions = (ListingOptions) ActionContext.getContext().getApplication().get(AdminConstants.LISTING_OPTIONS);
				List<AdditionalOptionsFees> additionalOptionsFeesList = (List<AdditionalOptionsFees>) ActionContext.getContext().getApplication().get(AdminConstants.OPTIONS_FEES);

				if(uploadedFiles.size() >= listingOptions.getNumberOfFilesAllowedToUpload()) {
					addActionError("You can not upload more than " + listingOptions.getNumberOfFilesAllowedToUpload() + " files.");
				} else if(upload != null && (upload.length() / 1024) > listingOptions.getMaximumUploadFileSize()) {
					addActionError("You can not upload file with size more than " + listingOptions.getMaximumUploadFileSize() + " Kb.");
				}  else if(listingOptions.getAllowAnyFileTypeToUpload().equalsIgnoreCase("false") && !isCorrectFileExtention(listingOptions.getFilesExtensionsAllowed(), getUploadFileName())) {
					addActionError("You can not upload file other than " + listingOptions.getFilesExtensionsAllowed());
				} else if(totalFileSize > listingOptions.getMaximumUploadTotalFilesSize()) {
					addActionError("Your total upload size exeeds " + listingOptions.getFilesExtensionsAllowed() + " Kb.");
				} else {
					String method = "getAuction";
					int type = Integer.parseInt(request.getParameter("type"));
					if(type == 2)
						method = "getFixedPrice";
					else if(type == 3)
						method = "getShop";

					UploadedFile uploadedFile = new UploadedFile();
					tempFile = File.createTempFile("MyFile.txt", ".tmp" );
					FileUtils.copyFile(upload, tempFile);
					uploadedFile.setName(tempFile.getName());
					uploadedFile.setSize(tempFile.length());
					uploadedFile.setContentType(getUploadContentType());
					uploadedFiles.add(uploadedFile);
					if(uploadedFiles.size() == 1) {
						this.fileFees = Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(10), method).toString());
					} else if(uploadedFiles.size() == 2) {
						this.fileFees = Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(11), method).toString());
					} else if(uploadedFiles.size() == 3) {
						this.fileFees = Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(12), method).toString());
					} else if(uploadedFiles.size() == 4) {
						this.fileFees = Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(13), method).toString());
					} else if(uploadedFiles.size() >= 5) {
						this.fileFees = Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(14), method).toString());
					}
					ActionContext.getContext().getSession().put("uploadedFiles", uploadedFiles);
					System.out.println("Path : " + tempFile.getAbsolutePath());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		languageList  = (List<Languages>) ActionContext.getContext().getApplication().get(AdminConstants.LANGUAGES);
		return INPUT;
	}

	public String showAuctions() {
		ActionContext.getContext().getSession().put("uploadedFiles", null);
		languageList  = (List<Languages>) ActionContext.getContext().getApplication().get(AdminConstants.LANGUAGES);

		try{
			if (request.getParameter("itemId") != null) {
				String itemId = request.getParameter("itemId");
				this.items = ItemsServiceDelegator.getItemsById(Integer.parseInt(itemId));
				user = items.getUserId();
				countryList = LocationCategoriesServiceDelegator.getCountryListByRegionIdWOS(user.getRegion().getCategoryId());
				stateList = LocationCategoriesServiceDelegator.getStateListByCountryIdWOS(user.getCountry().getCategoryId());

				if(criterionList.size() > 0){
	                 criterionList.clear();
	            }
	            criterionList.add(Restrictions.eq("itemId", this.items));
	            List<ItemCategories> itemCategoriesList = (List<ItemCategories>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, ItemCategories.class);
	            if(itemCategoriesList != null && itemCategoriesList.size() > 0){
	                 int index = 0;
	                 editCategories = new String[itemCategoriesList.size()];
	                 for (Iterator iterator = itemCategoriesList.iterator(); iterator.hasNext();) {
	                      ItemCategories itemCategories = (ItemCategories) iterator.next();
	                      int categoryId = itemCategories.getCategoryId().getCategoryId();
	                      editCategories[index] = String.valueOf(categoryId);
	                      index++;
	                 }
	            }
	            if(editCategories != null && editCategories.length > 0){
	            	editbackCategories = new String[itemCategoriesList.size()];
		            for (int index = 0; index < editCategories.length; index++) {
		                 DynamicTreeSelectAction dynamicTreeSelectAction = new DynamicTreeSelectAction();
		                 String[] categoryList = dynamicTreeSelectAction.getGeneralCategoriesFromCategoryId(Integer.parseInt(editCategories[index]));
		                 editbackCategories[index] = "";

		                 for (String str : categoryList) {
		                	 editbackCategories[index] += (str + "->");
		                 }
		                 editbackCategories[index] = editbackCategories[index].substring(0, editbackCategories[index].length() - 2);
		            }
		        }

				System.out.println(request.getParameter("action"));
				if((!request.getParameter("action").equals(null)) && (request.getParameter("action").trim().equalsIgnoreCase("copyAuction"))){
					this.action = "copySellAuctions";
				}
				if((!request.getParameter("action").equals(null)) && (request.getParameter("action").trim().equalsIgnoreCase("copyFixedPrice"))){
					this.action = "copySellFixedPrice";
				}
				if((!request.getParameter("action").equals(null)) && (request.getParameter("action").trim().equalsIgnoreCase("copyShops"))){
					this.action = "copySellShops";
				}
			}
			languageList  = (List<Languages>) ActionContext.getContext().getApplication().get(AdminConstants.LANGUAGES);
			ActionContext.getContext().getSession().put("uploadedFiles", null);
			setDefaultValues();
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String backAction() {
		this.items = (Items) ActionContext.getContext().getSession().get("items");
		this.categories = (String[]) ActionContext.getContext().getSession().get("categories");
		this.backCategories = (String[]) ActionContext.getContext().getSession().get("backCategories");
		this.uploadedFiles = (List<UploadedFile>) ActionContext.getContext().getSession().get("uploadedFiles");

		countryList = LocationCategoriesServiceDelegator.getCountryListByRegionIdWOS(this.items.getLocationCategoriesByRegion().getCategoryId());
		stateList = LocationCategoriesServiceDelegator.getStateListByCountryIdWOS(this.items.getLocationCategoriesByCountry().getCategoryId());
		languageList  = (List<Languages>) ActionContext.getContext().getApplication().get(AdminConstants.LANGUAGES);

		setDefaultValues();
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	public String previewAuctions() {
		setLeftAllowed(false);
		setMyAccount(false);

		this.backAction = "backToSellAddAuctions";

		if(request.getParameter("itemId") != null && request.getParameter("action").trim().equalsIgnoreCase("submitsimilarAuction")){
			String itemId = request.getParameter("itemId");
			this.items = ItemsServiceDelegator.getItemsById(Integer.parseInt(itemId));
		}

		if(request.getParameter("action") != null && request.getParameter("action").equalsIgnoreCase("copySellAuctions")){
			this.action = "copySellAuctions";
		}else if (request.getParameter("items.itemId") != null && !request.getParameter("items.itemId").equals("")) {
			this.action = "updateSellAuctions";
		}else{
			this.action = "submitSellAuctions";
		}
		request.getSession().setAttribute("itemId", this.items.getItemId());
		if(request.getParameterValues("categoryId") != null){
            categories = request.getParameterValues("categoryId");
        }else {
            if(criterionList.size() > 0){
                 criterionList.clear();
            }

            criterionList.add(Restrictions.eq("itemId", this.items));
            List<ItemCategories> itemCategoriesList = (List<ItemCategories>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, ItemCategories.class);
            if(itemCategoriesList != null && itemCategoriesList.size() > 0){
                 int index = 0;
                 categories = new String[itemCategoriesList.size()];
                 for (Iterator iterator = itemCategoriesList.iterator(); iterator.hasNext();) {
                      ItemCategories itemCategories = (ItemCategories) iterator.next();
                      int categoryId = itemCategories.getCategoryId().getCategoryId();
                      categories[index] = String.valueOf(categoryId);
                      index++;
                 }
            }
        }

        if(categories != null && categories.length > 0){
            this.backCategories = new String[categories.length];

            for (int index = 0; index < categories.length; index++) {
                 DynamicTreeSelectAction dynamicTreeSelectAction = new DynamicTreeSelectAction();
                 String[] categoryList = dynamicTreeSelectAction.getGeneralCategoriesFromCategoryId(Integer.parseInt(categories[index]));
                 backCategories[index] = "";

                 for (String str : categoryList) {
                	 backCategories[index] += (str + "->");
                 }

                 backCategories[index] = backCategories[index].substring(0, backCategories[index].length() - 2);
            }
        }

		if(ActionContext.getContext().getSession().get("uploadedFiles") != null) {
			this.uploadedFiles = (List<UploadedFile>) ActionContext.getContext().getSession().get("uploadedFiles");
		}

		try {
			if (this.thumbnailId != null) {
				File file = new File(System.getProperty("java.io.tmpdir") + "\\" + this.uploadedFiles.get(this.thumbnailId).getName());
				this.items.setThumbImage(CommonUtil.getBytesFromFile(file));
			}

			if (this.gallaryId != null) {
				File file = new File(System.getProperty("java.io.tmpdir") + "\\" + this.uploadedFiles.get(this.thumbnailId).getName());
				this.items.setGalleryImage(CommonUtil.getBytesFromFile(file));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		this.items.setLocationCategoriesByRegion(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByRegion().getCategoryId()));
		this.items.setLocationCategoriesByCountry(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByCountry().getCategoryId()));
		this.items.setLocationCategoriesByState(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByState().getCategoryId()));
		this.items.setItemLanguage(TranslationSystemServiceDelegator.get(this.items.getItemLanguage().getLanguageCode()));
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.setAttribute("id", 1);
		List<Itemtype> itemTypeList = (List<Itemtype>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, Itemtype.class);
		if(itemTypeList != null)
			this.items.setItemtype((Itemtype) itemTypeList.get(0));

		((List<AdditionalCategories>) ActionContext.getContext().getApplication().get(AdminConstants.CATEGORY_FEES)).get(0).getAuction();
		ActionContext.getContext().getSession().put("items", this.items);
		ActionContext.getContext().getSession().put("categories", categories);
		ActionContext.getContext().getSession().put("backCategories", this.backCategories);
		//ActionContext.getContext().getSession().put("items", this.items);

		feesCalculation(1);

		return SUCCESS;
	}

	public String updateSellAuctions(){
		try{
			Items item = ItemsServiceDelegator.getItemsById(this.items.getItemId());
			this.items = (Items) ActionContext.getContext().getSession().get("items");
			this.items.setUserId(item.getUserId());
			//this.items.setGeneralCategories(item.getGeneralCategories());
			this.items.setItemtype(item.getItemtype());
			CommonFunctionDelegator.generalUpdatebyobj(this.items);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String copySellAuctions(){

		return SUCCESS;
	}

	public String previewFixedPriceItem() {
		setLeftAllowed(false);
		setMyAccount(false);

		this.backAction = "backToFixedPriceItem";

		if(request.getParameter("itemId") != null && request.getParameter("action").trim().equalsIgnoreCase("submitsimilarFixedPrice")){
			String itemId = request.getParameter("itemId");
			this.items = ItemsServiceDelegator.getItemsById(Integer.parseInt(itemId));
		}
		System.out.println(action);
		if(request.getParameter("action") != null && request.getParameter("action").equalsIgnoreCase("copySellFixedPrice")){
			this.action = "copySellFixedPrice";
		}else if (request.getParameter("items.itemId") != null && !request.getParameter("items.itemId").equals("")) {
			this.action = "updateSellFixedPrice";
		}else{
			this.action = "submitFixedPriceItem";
		}

		if(request.getParameterValues("categoryId") != null){
            categories = request.getParameterValues("categoryId");
        }else {
            if(criterionList.size() > 0){
                 criterionList.clear();
            }
            criterionList.add(Restrictions.eq("itemId", this.items));
            List<ItemCategories> itemCategoriesList = (List<ItemCategories>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, ItemCategories.class);
            if(itemCategoriesList != null && itemCategoriesList.size() > 0){
                 int index = 0;
                 categories = new String[itemCategoriesList.size()];
                 for (Iterator iterator = itemCategoriesList.iterator(); iterator.hasNext();) {
                      ItemCategories itemCategories = (ItemCategories) iterator.next();
                      int categoryId = itemCategories.getCategoryId().getCategoryId();
                      categories[index] = String.valueOf(categoryId);
                      index++;
                 }
            }
        }

		 if(categories != null && categories.length > 0){
	            this.backCategories = new String[categories.length];

	            for (int index = 0; index < categories.length; index++) {
	                 DynamicTreeSelectAction dynamicTreeSelectAction = new DynamicTreeSelectAction();
	                 String[] categoryList = dynamicTreeSelectAction.getGeneralCategoriesFromCategoryId(Integer.parseInt(categories[index]));
	                 backCategories[index] = "";

	                 for (String str : categoryList) {
	                	 backCategories[index] += (str + "->");
	                 }

	                 backCategories[index] = backCategories[index].substring(0, backCategories[index].length() - 2);
	            }
	       }

		this.items.setLocationCategoriesByRegion(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByRegion().getCategoryId()));
		this.items.setLocationCategoriesByCountry(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByCountry().getCategoryId()));
		this.items.setLocationCategoriesByState(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByState().getCategoryId()));
		this.items.setItemLanguage(TranslationSystemServiceDelegator.get(this.items.getItemLanguage().getLanguageCode()));
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.setAttribute("id", 2);
		List<Itemtype> itemTypeList = (List<Itemtype>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, Itemtype.class);
		if(itemTypeList != null)
			this.items.setItemtype((Itemtype) itemTypeList.get(0));

		((List<AdditionalCategories>) ActionContext.getContext().getApplication().get(AdminConstants.CATEGORY_FEES)).get(0).getAuction();
		ActionContext.getContext().getSession().put("items", this.items);
		ActionContext.getContext().getSession().put("categories", request.getParameterValues("categoryId"));
		feesCalculation(2);

		return SUCCESS;
	}

	public String updateSellFixedPrice(){
		try{
			Items item = ItemsServiceDelegator.getItemsById(this.items.getItemId());
			this.items = (Items) ActionContext.getContext().getSession().get("items");
			this.items.setUserId(item.getUserId());
			//this.items.setGeneralCategories(item.getGeneralCategories());
			this.items.setItemtype(item.getItemtype());
			CommonFunctionDelegator.generalUpdatebyobj(this.items);
		}catch (Exception e) {
			return INPUT;
		}
		feesCalculation(2);
		return SUCCESS;
	}

	public String previewShopItem() {
		setLeftAllowed(false);
		setMyAccount(false);

		this.backAction = "backToShopItem";

		if(request.getParameter("itemId") != null && request.getParameter("action").trim().equalsIgnoreCase("submitsimilarShops")){
			String itemId = request.getParameter("itemId");
			this.items = ItemsServiceDelegator.getItemsById(Integer.parseInt(itemId));
		}
		System.out.println(action);
		if(request.getParameter("action") != null && request.getParameter("action").equalsIgnoreCase("copySellShops")){
			this.action = "copySellShops";
		}else if (request.getParameter("items.itemId") != null && !request.getParameter("items.itemId").equals("")) {
			this.action = "updateSellShops";
		}else{
			this.action = "submitShopItem";
		}

		if(request.getParameterValues("categoryId") != null){
            categories = request.getParameterValues("categoryId");
        }else {
            if(criterionList.size() > 0){
                 criterionList.clear();
            }

            criterionList.add(Restrictions.eq("itemId", this.items));
            List<ItemCategories> itemCategoriesList = (List<ItemCategories>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, ItemCategories.class);
            if(itemCategoriesList != null && itemCategoriesList.size() > 0){
                 int index = 0;
                 categories = new String[itemCategoriesList.size()];
                 for (Iterator iterator = itemCategoriesList.iterator(); iterator.hasNext();) {
                      ItemCategories itemCategories = (ItemCategories) iterator.next();
                      int categoryId = itemCategories.getCategoryId().getCategoryId();
                      categories[index] = String.valueOf(categoryId);
                      index++;
                 }
            }
        }

		 if(categories != null && categories.length > 0){
	            this.backCategories = new String[categories.length];

	            for (int index = 0; index < categories.length; index++) {
	                 DynamicTreeSelectAction dynamicTreeSelectAction = new DynamicTreeSelectAction();
	                 String[] categoryList = dynamicTreeSelectAction.getGeneralCategoriesFromCategoryId(Integer.parseInt(categories[index]));
	                 backCategories[index] = "";

	                 for (String str : categoryList) {
	                	 backCategories[index] += (str + "->");
	                 }

	                 backCategories[index] = backCategories[index].substring(0, backCategories[index].length() - 2);
	            }
	        }

		this.items.setLocationCategoriesByRegion(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByRegion().getCategoryId()));
		this.items.setLocationCategoriesByCountry(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByCountry().getCategoryId()));
		this.items.setLocationCategoriesByState(LocationCategoriesServiceDelegator.getWOS(this.items.getLocationCategoriesByState().getCategoryId()));
		this.items.setItemLanguage(TranslationSystemServiceDelegator.get(this.items.getItemLanguage().getLanguageCode()));
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.setAttribute("id", 3);
		List<Itemtype> itemTypeList = (List<Itemtype>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, Itemtype.class);
		if(itemTypeList != null)
			this.items.setItemtype((Itemtype) itemTypeList.get(0));

		((List<AdditionalCategories>) ActionContext.getContext().getApplication().get(AdminConstants.CATEGORY_FEES)).get(0).getAuction();
		ActionContext.getContext().getSession().put("items", this.items);
		ActionContext.getContext().getSession().put("categories", request.getParameterValues("categoryId"));
		feesCalculation(3);

		return SUCCESS;
	}
	public String updateSellShops(){
		try{
			Items item = ItemsServiceDelegator.getItemsById(this.items.getItemId());
			this.items = (Items) ActionContext.getContext().getSession().get("items");
			this.items.setUserId(item.getUserId());
			//this.items.setGeneralCategories(item.getGeneralCategories());
			this.items.setItemtype(item.getItemtype());
			CommonFunctionDelegator.generalUpdatebyobj(this.items);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}
	public String submitSellAuctions() {
		GeneralOptions generalOptions = (GeneralOptions) ActionContext.getContext().getApplication().get(AdminConstants.GENERAL_OPTIONS);
		User tmpUser = SessionUtil.getUser(this.request);
		fees = Double.valueOf(request.getParameter("feesCharge"));

		if(CommonFunctionDelegator.getCountByCriterion(criterionList, Items.class) > generalOptions.getUserMaximumAllowedItemsToSell()) {
			addActionMessage("You can not sell more than " + generalOptions.getUserMaximumAllowedItemsToSell() + " item(s).");
		} else if(generalOptions.getRequiredPositiveBalanceForSelling() >= tmpUser.getCurrentBalance()) {
			addActionMessage("You should have enough balance for creating an item.");
		} else if(generalOptions.getMaximumAllowedNegativeBalance() > (tmpUser.getCurrentBalance() - fees)) {
			addActionMessage("You do not have enough balance.");
		} else {
			this.items = (Items) ActionContext.getContext().getSession().get("items");
			this.items.setUserId(tmpUser);
			this.items.setStartTime(DateUtil.getTodaysDate());
			this.items.setEndTime(DateUtil.addDate(this.items.getStartTime(), Calendar.DATE, Integer.parseInt(this.items.getDuration())));
			this.items.setStatus(new BidStatus(4));
			AuctionServiceDelegator.saveAuctionSell(items);
			/* Update count for auction.*/
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
		    myAccountCount.setSellingAuction(myAccountCount.getSellingAuction() + 1);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);

			Transactions transactions = new Transactions();
			transactions.setAmount(fees);
			transactions.setBalance(tmpUser.getCurrentBalance() - fees);
			transactions.setDate(DateUtil.getTodaysDate());
			transactions.setTitle(this.items.getTitle());
			transactions.setUser(tmpUser);
			CommonFunctionDelegator.generalInsertbyobj(transactions);

			if(ActionContext.getContext().getSession().get("uploadedFiles") != null) {
				uploadedFiles = (List<UploadedFile>) ActionContext.getContext().getSession().get("uploadedFiles");
				String path = servletContext.getRealPath("/upload");
				for (UploadedFile uploadedFile : uploadedFiles) {
					File srcFile = new File(System.getProperty("java.io.tmpdir") + "\\" + uploadedFile.getName());
					File destFile = new File(path + "\\" + uploadedFile.getName());

					try {
						FileUtils.copyFile(srcFile, destFile);
					} catch (IOException e) {
						e.printStackTrace();
					}

					ItemAuctionImageId itemAuctionImage = new ItemAuctionImageId();
					itemAuctionImage.setItems(this.items);
					itemAuctionImage.setUser(tmpUser);
					itemAuctionImage.setImagePath("upload/" + uploadedFile.getName());
					itemAuctionImage.setContentType(uploadedFile.getContentType());

					ItemAuctionImage itemAuctionImage2 = new ItemAuctionImage();
					itemAuctionImage2.setId(itemAuctionImage);
					CommonFunctionDelegator.generalInsertbyobj(itemAuctionImage2);
				}
			}

			String[] categories = (String[]) ActionContext.getContext().getSession().get("categories");

			for (String categoryId : categories) {
				ItemCategories itemCategories = new ItemCategories();
				itemCategories.setCategoryId(CategoryManagerServiceDelegator.getWOS(Integer.parseInt(categoryId)));
				itemCategories.setItemId(this.items);
				CommonFunctionDelegator.generalInsertbyobj(itemCategories);
			}

			SessionUtil.getUser(request).setCurrentBalance(SessionUtil.getUser(request).getCurrentBalance() - fees);
			CommonFunctionDelegator.generalUpdatebyobj(SessionUtil.getUser(request));
			request.getSession().setAttribute("itemId", this.items.getItemId());
			ActionContext.getContext().getSession().put("items", null);
			ActionContext.getContext().getSession().put("categories", null);

			if(criterionList.size() > 0 ){
		    	criterionList.clear();
		    }

		}

		return SUCCESS;
	}

	public String submitFixedPriceItem() {
		GeneralOptions generalOptions = (GeneralOptions) ActionContext.getContext().getApplication().get(AdminConstants.GENERAL_OPTIONS);
		User tmpUser = SessionUtil.getUser(this.request);
		fees = Double.valueOf(request.getParameter("feesCharge"));

		if(CommonFunctionDelegator.getCountByCriterion(criterionList, Items.class) > generalOptions.getUserMaximumAllowedItemsToSell()) {
			addActionMessage("You can not sell more than " + generalOptions.getUserMaximumAllowedItemsToSell() + " item(s).");
		} else if(generalOptions.getRequiredPositiveBalanceForSelling() >= tmpUser.getCurrentBalance()) {
			addActionMessage("You should have enough balance for creating an item.");
		} else if(generalOptions.getMaximumAllowedNegativeBalance() > (tmpUser.getCurrentBalance() - fees)) {
			addActionMessage("You do not have enough balance.");
		} else {
			this.items = (Items) ActionContext.getContext().getSession().get("items");
			user = SessionUtil.getUser(this.request);
			this.items.setUserId(tmpUser);
			this.items.setStartTime(DateUtil.getTodaysDate());
			this.items.setEndTime(DateUtil.addDate(this.items.getStartTime(), Calendar.DATE, Integer.parseInt(this.items.getDuration())));
			this.items.setStatus(new BidStatus(4));
			AuctionServiceDelegator.saveAuctionSell(this.items);

			/* Update count for fixed price.*/
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
			myAccountCount.setSellingFixedPrice(myAccountCount.getSellingFixedPrice() + 1);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);

			Transactions transactions = new Transactions();
			transactions.setAmount(fees);
			transactions.setBalance(tmpUser.getCurrentBalance() - fees);
			transactions.setDate(DateUtil.getTodaysDate());
			transactions.setTitle(this.items.getTitle());
			transactions.setUser(tmpUser);
			CommonFunctionDelegator.generalInsertbyobj(transactions);

			if(ActionContext.getContext().getSession().get("uploadedFiles") != null) {
				uploadedFiles = (List<UploadedFile>) ActionContext.getContext().getSession().get("uploadedFiles");
				String path = servletContext.getRealPath("/upload");
				for (UploadedFile uploadedFile : uploadedFiles) {
					File srcFile = new File(System.getProperty("java.io.tmpdir") + "\\" + uploadedFile.getName());
					File destFile = new File(path + "\\" + uploadedFile.getName());

					try {
						FileUtils.copyFile(srcFile, destFile);
					} catch (IOException e) {
						e.printStackTrace();
					}

					ItemAuctionImageId itemAuctionImage = new ItemAuctionImageId();
					itemAuctionImage.setItems(this.items);
					itemAuctionImage.setUser(tmpUser);
					itemAuctionImage.setImagePath("upload/" + uploadedFile.getName());
					itemAuctionImage.setContentType(uploadedFile.getContentType());

					ItemAuctionImage itemAuctionImage2 = new ItemAuctionImage();
					itemAuctionImage2.setId(itemAuctionImage);
					CommonFunctionDelegator.generalInsertbyobj(itemAuctionImage2);
				}

			}

			String[] categories = (String[]) ActionContext.getContext().getSession().get("categories");

			for (String categoryId : categories) {
				ItemCategories itemCategories = new ItemCategories();
				itemCategories.setCategoryId(CategoryManagerServiceDelegator.getWOS(Integer.parseInt(categoryId)));
				itemCategories.setItemId(this.items);
				CommonFunctionDelegator.generalInsertbyobj(itemCategories);
			}
			SessionUtil.getUser(request).setCurrentBalance(SessionUtil.getUser(request).getCurrentBalance() - fees);
			CommonFunctionDelegator.generalUpdatebyobj(SessionUtil.getUser(request));
			request.getSession().setAttribute("itemId", this.items.getItemId());
			ActionContext.getContext().getSession().put("items", null);
			ActionContext.getContext().getSession().put("categories", null);
		}

		return SUCCESS;
	}

	public String submitShopItem() {
		GeneralOptions generalOptions = (GeneralOptions) ActionContext.getContext().getApplication().get(AdminConstants.GENERAL_OPTIONS);
		User tmpUser = SessionUtil.getUser(this.request);
		fees = Double.valueOf(request.getParameter("feesCharge"));

		if(CommonFunctionDelegator.getCountByCriterion(criterionList, Items.class) > generalOptions.getUserMaximumAllowedItemsToSell()) {
			addActionMessage("You can not sell more than " + generalOptions.getUserMaximumAllowedItemsToSell() + " item(s).");
		} else if(generalOptions.getRequiredPositiveBalanceForSelling() >= tmpUser.getCurrentBalance()) {
			addActionMessage("You should have enough balance for creating an item.");
		} else if(generalOptions.getMaximumAllowedNegativeBalance() > (tmpUser.getCurrentBalance() - fees)) {
			addActionMessage("You do not have enough balance.");
		} else {
			this.items = (Items) ActionContext.getContext().getSession().get("items");
			this.items.setUserId(tmpUser);
			this.items.setStartTime(DateUtil.getTodaysDate());
			this.items.setEndTime(DateUtil.addDate(this.items.getStartTime(), Calendar.DATE, Integer.parseInt(this.items.getDuration())));
			this.items.setStatus(new BidStatus(4));
			AuctionServiceDelegator.saveAuctionSell(this.items);
			/* Update count for shops.*/
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
			myAccountCount.setSellingFixedPrice(myAccountCount.getSellingFixedPrice() + 1);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);

			Transactions transactions = new Transactions();
			transactions.setAmount(fees);
			transactions.setBalance(tmpUser.getCurrentBalance() - fees);
			transactions.setDate(DateUtil.getTodaysDate());
			transactions.setTitle(this.items.getTitle());
			transactions.setUser(tmpUser);
			CommonFunctionDelegator.generalInsertbyobj(transactions);

			if(ActionContext.getContext().getSession().get("uploadedFiles") != null) {
				uploadedFiles = (List<UploadedFile>) ActionContext.getContext().getSession().get("uploadedFiles");
				String path = servletContext.getRealPath("/upload");
				for (UploadedFile uploadedFile : uploadedFiles) {
					File srcFile = new File(System.getProperty("java.io.tmpdir") + "\\" + uploadedFile.getName());
					File destFile = new File(path + "\\" + uploadedFile.getName());

					try {
						FileUtils.copyFile(srcFile, destFile);
					} catch (IOException e) {
						e.printStackTrace();
					}

					ItemAuctionImageId itemAuctionImage = new ItemAuctionImageId();
					itemAuctionImage.setItems(this.items);
					itemAuctionImage.setUser(tmpUser);
					itemAuctionImage.setImagePath("upload/" + uploadedFile.getName());
					itemAuctionImage.setContentType(uploadedFile.getContentType());

					ItemAuctionImage itemAuctionImage2 = new ItemAuctionImage();
					itemAuctionImage2.setId(itemAuctionImage);
					CommonFunctionDelegator.generalInsertbyobj(itemAuctionImage2);
				}
			}

			String[] categories = (String[]) ActionContext.getContext().getSession().get("categories");

			for (String categoryId : categories) {
				ItemCategories itemCategories = new ItemCategories();
				itemCategories.setCategoryId(CategoryManagerServiceDelegator.getWOS(Integer.parseInt(categoryId)));
				itemCategories.setItemId(this.items);
				CommonFunctionDelegator.generalInsertbyobj(itemCategories);
			}
			SessionUtil.getUser(request).setCurrentBalance(SessionUtil.getUser(request).getCurrentBalance() - fees);
			CommonFunctionDelegator.generalUpdatebyobj(SessionUtil.getUser(request));
			request.getSession().setAttribute("itemId", this.items.getItemId());
			ActionContext.getContext().getSession().put("items", null);
			ActionContext.getContext().getSession().put("categories", null);
		}
		return SUCCESS;
	}

	public String saveUpdateAutionItem() throws Exception{
		for (File path : file) {

//			String contentType = request.getContentType();
//  			System.out.println(contentType);
//  			InputStream is = request.getInputStream();
//
//  			int formDataLength = request.getContentLength();
//
//			FileUtil.fileUpload(contentType, is, formDataLength );
		//}
		/*if(items.getTitle() != null){
			this.items.setUserId(SessionUtil.getUser(request).getId());
			AuctionServiceDelegator.saveAuctionSell(items);
			return SUCCESS;
		}else{
			addActionError("Insert Valida Information required by Auction");
			return INPUT;
		}*/
//			String fullFileName = "c:/upload/myfile.txt";
//
//			File theFile = new File(fullFileName);
//
//			FileUtils.copyFile(upload, theFile);
//
//			} catch (Exception e) {
//
//			addActionError(e.getMessage());
//
//			return INPUT;
//
//			}
		 try{
              	System.out.println("Inside Upload");
              	File destDir = new  File("c:\\");
                System.out.println("File Name:"+this.getMyfileFileName());
                System.out.println("File ContentType:"+this.getMyfileContentType());

                FileUtils.copyFileToDirectory(path, destDir);
                return SUCCESS; // redirect to welcome page.
            }catch(Exception exp){
                LOG.error("File Upload Error:"+  exp);
                this.addActionError("File Upload Error:"+ exp);
                return INPUT;
            }
		}
		return SUCCESS;
}


	/**
	 * @return the languageList
	 */
	public List<Languages> getLanguageList() {
		return languageList;
	}

	/**
	 * @param languageList the languageList to set
	 */
	public void setLanguageList(List<Languages> languageList) {
		this.languageList = languageList;
	}

	/**
	 * @return the items
	 */
	public Items getItems() {
		return items;
	}

	/**
	 * @param items the items to set
	 */
	public void setItems(Items items) {
		this.items = items;
	}

	public String getMyfileContentType() {
		return myfileContentType;
	}

	public void setMyfileContentType(String myfileContentType) {
		this.myfileContentType = myfileContentType;
	}

	public String getMyfileFileName() {
		return myfileFileName;
	}

	public void setMyfileFileName(String myfileFileName) {
		this.myfileFileName = myfileFileName;
	}

	public List<LocationCategoriesWOS> getRegionList() {
		return regionList;
	}

	public List<ShippingOptions> getShippingTimeList() {
		return shippingTimeList;
	}

	public List<ShippingOptions> getShippingCostChargesList() {
		return shippingCostChargesList;
	}

	public List<ShippingOptions> getShippingInsuranceList() {
		return shippingInsuranceList;
	}

	public List<ShippingOptions> getReturnPeriodList() {
		return returnPeriodList;
	}

	public List<ShippingOptions> getRefundMethodList() {
		return refundMethodList;
	}

	public List<ShippingOptions> getShipToList() {
		return shipToList;
	}

	public List<Currency> getCurrency() {
		return currency;
	}

	public String getAction() {
		return action;
	}

//	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public List<UploadedFile> getUploadedFiles() {
		return uploadedFiles;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<LocationCategoriesWOS> getCountryList() {
		return countryList;
	}

	public void setCountryList(List<LocationCategoriesWOS> countryList) {
		this.countryList = countryList;
	}

	public List<LocationCategoriesWOS> getStateList() {
		return stateList;
	}

	public void setStateList(List<LocationCategoriesWOS> stateList) {
		this.stateList = stateList;
	}


	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#validate()
	 */
	@Override
	public void validate() {
		super.validate();
		setDefaultValues();
		ListingOptions listingOptions = (ListingOptions) ActionContext.getContext().getApplication().get(AdminConstants.LISTING_OPTIONS);
		languageList  = (List<Languages>) ActionContext.getContext().getApplication().get(AdminConstants.LANGUAGES);
		String[] words = listingOptions.getBannedWords().split(",");

		List<AdditionalCategories> additionalCategoriesList = (List<AdditionalCategories>) ActionContext.getContext().getApplication().get(AdminConstants.CATEGORY_FEES);

		if(this.items.getTitle().length() > listingOptions.getMaximumTitleSizeInBytes().intValue()) {
			addFieldError("items.title", "Title length can't be more than " + listingOptions.getMaximumTitleSizeInBytes().intValue());
		} else if (CommonUtil.isContainsBannedWords(words, this.items.getTitle())) {
			addFieldError("items.title", "Title contains banned word(s).");
		}

		if(this.items.getSubTitle().length() > listingOptions.getShortTitleSize().intValue()) {
			addFieldError("items.subTitle", "Sub-Title length can't be more than " + listingOptions.getShortTitleSize().intValue());
		} else if (CommonUtil.isContainsBannedWords(words, this.items.getSubTitle())) {
			addFieldError("items.subTitle", "Sub-Title contains banned word(s).");
		}

		if(this.items.getDescription().length() > listingOptions.getMaximumDescriptionSizeInBytes().intValue()) {
			addFieldError("items.description", "Description length can't be more than " + listingOptions.getMaximumDescriptionSizeInBytes().intValue());
		} else if (CommonUtil.isContainsBannedWords(words, this.items.getDescription())) {
			addFieldError("items.description", "Description contains banned word(s).");
		}

		if(request.getParameter("type") != null) {
			int type = Integer.parseInt(request.getParameter("type"));

			if(request.getParameter("categoryId") != null) {
				if(type == 1) {
					if(request.getParameterValues("categoryId").length > (int) additionalCategoriesList.get(0).getAuction().doubleValue()) {
						addActionError("You can not select more than " + (int) additionalCategoriesList.get(0).getAuction().doubleValue() + " Categories.");
					}
				} else if(type == 2) {
					if(request.getParameterValues("categoryId").length > (int) additionalCategoriesList.get(0).getFixedPrice().doubleValue()) {
						addActionError("You can not select more than " + (int) additionalCategoriesList.get(0).getFixedPrice().doubleValue() + " Categories.");
					}
				} else if(type == 3) {
					if(request.getParameterValues("categoryId").length > (int) additionalCategoriesList.get(0).getShop().doubleValue()) {
						addActionError("You can not select more than " + (int) additionalCategoriesList.get(0).getShop().doubleValue() + " Categories.");
					}
				}
			} else {
				addActionError("You must have to select a single category...");
			}
		}
	}

	private void feesCalculation(int type) {
		this.fees = 0;
		int totalFiles = this.uploadedFiles.size();
		String method = "getAuction";
		if(type == 2)
			method = "getFixedPrice";
		else if(type == 3)
			method = "getShop";

		List<AdditionalOptionsFees> additionalOptionsFeesList = (List<AdditionalOptionsFees>) ActionContext.getContext().getApplication().get(AdminConstants.OPTIONS_FEES);
		List<AdditionalCategories> additionalCategoriesFeesList = (List<AdditionalCategories>) ActionContext.getContext().getApplication().get(AdminConstants.CATEGORY_FEES);
		List<AuctionListingFees> auctionListingFeesList = (List<AuctionListingFees>) ActionContext.getContext().getApplication().get(AdminConstants.REGULAR_AUCTION_OPTIONS);
		MiscellaneousFees miscellaneousFees = (MiscellaneousFees) ActionContext.getContext().getApplication().get(AdminConstants.MISCELLANEOUS_FEES);

		for (AuctionListingFees auctionListingFees : auctionListingFeesList) {
			if(this.items.getStartBid() >= auctionListingFees.getStartingPriceFrom() && this.items.getStartBid() <= auctionListingFees.getStartingPriceTo()) {
				this.regularInsertionFees = auctionListingFees.getAuction();
			}
		}

		if(this.items.getQuantity() > 1) {
			this.regularInsertionFees += miscellaneousFees.getDutchAuctionsMaximumFees();
		}

		if(this.items.getHomePageFeatured()) {
			System.out.println();

			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(0), method).toString());
		}
		if(this.items.getCategoryFeatured()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(1), method).toString());
		}
		if(this.items.getGallery() != null && this.items.getGallery()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(2), method).toString());
		}
		if(this.items.getGalleryFeatured() != null && this.items.getGalleryFeatured()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(3), method).toString());
		}
		if(this.items.getGalleryPlus() != null && this.items.getGalleryPlus()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(4), method).toString());
		}
		if(this.items.getSubTitle().length() > 0) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(5), method).toString());
		}
		if(this.items.getBold()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(6), method).toString());
		}
		if(this.items.getColored().length() > 0) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(7), method).toString());
		}
		if(this.items.getBgColor().length() > 0) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(8), method).toString());
		}
		if(this.items.getGiftIcon().split(";")[0].length() > 0) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(9), method).toString());
		}
		if(totalFiles == 1) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(10), method).toString());
		} else if(totalFiles == 2) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(11), method).toString());
		} else if(totalFiles == 3) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(12), method).toString());
		} else if(totalFiles == 4) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(13), method).toString());
		} else if(totalFiles >= 5) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(14), method).toString());
		}
		if(this.items.getMediaShow() != null && this.items.getMediaShow() == 2) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(15), method).toString());
		}
		if(this.items.getHomePage().length() > 0) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(16), method).toString());
		}
		if(this.items.getCrossPromotion() == null){
		} else {
			if ((!this.items.getCrossPromotion().equals(""))
					&& (!this.items.getCrossPromotion().equals(null))) {
				if (Integer.parseInt(this.items.getCrossPromotion()) == 3) {
					this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(17), method).toString());
				} else if (Integer.parseInt(this.items.getCrossPromotion()) == 6) {
					this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(18), method).toString());
				} else if (Integer.parseInt(this.items.getCrossPromotion()) == 9) {
					this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(19), method).toString());
				}
			}
		}
		if(this.items.getPrivateAuction() != null && this.items.getPrivateAuction()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(20), method).toString());
		}
		if(this.items.getFramed() != null && this.items.getFramed()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(21), method).toString());
		}
		if(this.items.getCompanyProfile() != null && this.items.getCompanyProfile()) {
			this.fees += Double.valueOf(CommonUtil.callMethod(AdditionalOptionsFees.class, additionalOptionsFeesList.get(22), method).toString());
		}

		double categoryFee = 0;
		if(request.getParameterValues("categoryId") == null){

		}else {
		for (String category : request.getParameterValues("categoryId")) {
			int level = CategoryManagerServiceDelegator.get(Integer.parseInt(category)).getLevel();
			if(level == 2)
				categoryFee += (((this.regularInsertionFees + this.fees) * Double.valueOf(CommonUtil.callMethod(AdditionalCategories.class, additionalCategoriesFeesList.get(1), method).toString())) / 100);
			else if(level == 3)
				categoryFee += (((this.regularInsertionFees + this.fees) * Double.valueOf(CommonUtil.callMethod(AdditionalCategories.class, additionalCategoriesFeesList.get(2), method).toString())) / 100);
			if(level > 3)
				categoryFee += (((this.regularInsertionFees + this.fees) * Double.valueOf(CommonUtil.callMethod(AdditionalCategories.class, additionalCategoriesFeesList.get(3), method).toString())) / 100);
		}}

		this.fees += categoryFee;
	}

	public double getFees() {
		return fees;
	}

	public double getRegularInsertionFees() {
		return regularInsertionFees;
	}

	private boolean isCorrectFileExtention(String extentions, String fileExtention) {
		boolean flag = false;

		if(fileExtention == null)
			return false;

		String str = fileExtention.substring(fileExtention.lastIndexOf(".") + 1, fileExtention.length());
		String[] tmpExtentions = extentions.split(" ");
		for (String tmpExtention : tmpExtentions) {
			if(tmpExtention.equalsIgnoreCase(str)) {
				flag = true;
				break;
			}
		}
		return flag;
	}

	private void setDefaultValues() {
		ListingOptions listingOptions = (ListingOptions) ActionContext.getContext().getApplication().get(AdminConstants.LISTING_OPTIONS);
		GeneralOptions generalOptions = (GeneralOptions) ActionContext.getContext().getApplication().get(AdminConstants.GENERAL_OPTIONS);

		if(this.items == null) {
			defaultLang = listingOptions.getDefaultItemLanguage();
			defaultRegion = listingOptions.getDefaultRegion();
			defaultCountry = listingOptions.getDefaultCountry();
			defaultCurrency = generalOptions.getCurrency().getCode();
		}
		else {
			defaultLang = this.items.getItemLanguage().getLanguageCode();
			defaultRegion = this.items.getLocationCategoriesByRegion().getCategoryId();
			defaultCountry = this.items.getLocationCategoriesByCountry().getCategoryId();
			defaultCurrency = this.items.getCurrency().getCode();
		}

		this.countryList = LocationCategoriesServiceDelegator.getCountryListByRegionIdWOS(defaultRegion);
		this.stateList = LocationCategoriesServiceDelegator.getStateListByCountryIdWOS(defaultCountry);
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public double getFileFees() {
		return fileFees;
	}

	public String[] getCategories() {
		return categories;
	}

	public Integer getThumbnailId() {
		return thumbnailId;
	}

	public Integer getGallaryId() {
		return gallaryId;
	}

	public void setThumbnailId(Integer thumbnailId) {
		this.thumbnailId = thumbnailId;
	}

	public void setGallaryId(Integer gallaryId) {
		this.gallaryId = gallaryId;
	}

	public String getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public String[] getBackCategories() {
		return backCategories;
	}

	public String getBackAction() {
		return backAction;
	}

	public MyAccountCount getMyAccountCount() {
		return myAccountCount;
	}

	public void setMyAccountCount(MyAccountCount myAccountCount) {
		this.myAccountCount = myAccountCount;
	}

	public String getDefaultLang() {
		return defaultLang;
	}

	public int getDefaultRegion() {
		return defaultRegion;
	}

	public int getDefaultCountry() {
		return defaultCountry;
	}

	public String getDefaultCurrency() {
		return defaultCurrency;
	}

	public String[] getEditCategories() {
		return editCategories;
	}

	public void setEditCategories(String[] editCategories) {
		this.editCategories = editCategories;
	}

	public String[] getEditbackCategories() {
		return editbackCategories;
	}

	public void setEditbackCategories(String[] editbackCategories) {
		this.editbackCategories = editbackCategories;
	}
}
